package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingProjectPlanDto;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.service.NursingPlanService;

import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> all() {
        List<NursingPlanVo> nursingProjectpPlanVos = nursingPlanService.all();
        return success(nursingProjectpPlanVos);
    }

    @GetMapping("/search")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> list(@ApiParam(value = "护理计划名称", required = false) String name,
                                                            @ApiParam(value = "当前页码", defaultValue = "1") Integer pageNum,
                                                            @ApiParam(value = "当前页码", defaultValue = "10") Integer pageSize,
                                                            @ApiParam(value = "状态", required = false) Integer status) {

        PageResponse<NursingPlanVo> response = nursingPlanService.list(name, pageNum, pageSize, status);
        return success(response);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult add(@RequestBody NursingPlanDto planDto) {
        nursingPlanService.add(planDto);
        return success();

    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingPlanVo> findById(@PathVariable Long id) {

        return ResponseResult.success(nursingPlanService.findByid(id));
    }

    @PutMapping()
    @ApiOperation("根据id修改")
    public ResponseResult updata(@RequestBody NursingPlanDto nursingPlanDto) {

        nursingPlanService.updata(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除")
    public ResponseResult delete(@PathVariable Long id) {
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("禁用启用")
    public ResponseResult enableOrDisable(@PathVariable @ApiParam(value = "ID", required = true) Long id,
                                          @PathVariable @ApiParam(value = "状态", required = true) Integer status) {
        nursingPlanService.enableOrDisable(id, status);
        return success();
    }
}